package com.kingint.web.admin.base.controller;


import com.kingint.mbg.group.Insert;
import com.kingint.mbg.group.Update;
import com.kingint.web.util.validateUtil.ValidList;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.admin.base.service.BasOrderTypeHotelTimeService;
import com.kingint.mbg.bas.entity.BasOrderTypeHotelTime;


/**
 * @描述：酒店自定义上报时间表控制类
 * @作者: wxh
 * @日期: 2021-01-15
 */
@RestController
@RequestMapping("/basOrderTypeHotelTime")
@Api(value = "BasOrderTypeHotelTimeController", description = "酒店自定义上报时间表")
@CrossOrigin
public class BasOrderTypeHotelTimeController{

    @Autowired
    public BasOrderTypeHotelTimeService basOrderTypeHotelTimeService;


    @ApiOperation(value = "添加酒店自定义上报时间表")
    @PostMapping("/create")
    @PreAuthorize("hasAuthority('basOrderTypeHotelTime:create')")
    public Object create(@Validated(Insert.class) @RequestBody BasOrderTypeHotelTime basOrderTypeHotelTime){
        Boolean bool=basOrderTypeHotelTimeService.saveOrUpdate(basOrderTypeHotelTime);
        if(bool){
            return K.ok().data(basOrderTypeHotelTime.getId());
        }else{
            return K.error();
        }
    }

    @ApiOperation(value = "批量添加酒店自定义上报时间表")
    @PostMapping("/insertList")
    @PreAuthorize("hasAuthority('basOrderTypeHotelTime:insertList')")
    public Object create(@RequestBody @Validated(Insert.class)  ValidList<BasOrderTypeHotelTime> basOrderTypeHotelTime){
        Boolean bool=basOrderTypeHotelTimeService.saveOrUpdateBatch(basOrderTypeHotelTime);
        if(bool){
            return K.ok();
        }else{
            return K.error();
        }
    }

    @ApiOperation(value = "更新酒店自定义上报时间表")
    @PutMapping("/update")
    @PreAuthorize("hasAuthority('basOrderTypeHotelTime:update')")
    public Object update(@Validated(Update.class) @RequestBody BasOrderTypeHotelTime basOrderTypeHotelTime){
        Boolean bool= basOrderTypeHotelTimeService.updateById(basOrderTypeHotelTime);
        if(bool){
             return K.ok().data(basOrderTypeHotelTime.getId());
        }else{
             return K.error();
        }
    }


    @ApiOperation(value = "删除酒店自定义上报时间表")
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAuthority('basOrderTypeHotelTime:delete')")
    public Object delete(@PathVariable("id") Long id){
        Boolean bool= basOrderTypeHotelTimeService.removeById(id);
        if(bool){
            return K.ok();
        }else{
            return K.error();
        }
    }

    @ApiOperation(value = "根据酒店自定义上报时间表名称分页获取酒店自定义上报时间表列表")
    @GetMapping("/list")
    @PreAuthorize("hasAuthority('basOrderTypeHotelTime:list')")
    public Object getList(BasOrderTypeHotelTime basOrderTypeHotelTime,
    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
    @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize){
        Page<BasOrderTypeHotelTime> page = new Page<>(pageNum, pageSize);
        IPage<BasOrderTypeHotelTime> info=basOrderTypeHotelTimeService.page(page,null);
        return K.ok().data(info);
    }

    @ApiOperation(value = "根据编号查询酒店自定义上报时间表信息")
    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('basOrderTypeHotelTime:get')")
    public Object getItem(@PathVariable("id") Long id){
        BasOrderTypeHotelTime basOrderTypeHotelTime=basOrderTypeHotelTimeService.getById(id);
        return K.ok().data(basOrderTypeHotelTime);
    }
}